package com.ruoyi.project.user.kkuser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.user.kkuser.domain.KKUser;
import com.ruoyi.project.user.kkuser.service.IKKUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author shixiangwen
 * @date 2019-12-04
 */
@Controller
@RequestMapping("/user/kkuser")
public class KKUserController extends BaseController
{
    private String prefix = "user/kkuser";

    @Autowired
    private IKKUserService kKUserService;

    @RequiresPermissions("user:kkuser:view")
    @GetMapping()
    public String kkuser()
    {
        return prefix + "/kkuser";
    }

    /**
     * 查询用户列表
     */
    @RequiresPermissions("user:kkuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(KKUser kKUser)
    {
        startPage();
        List<KKUser> list = kKUserService.selectKKUserList(kKUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @RequiresPermissions("user:kkuser:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(KKUser kKUser)
    {
        List<KKUser> list = kKUserService.selectKKUserList(kKUser);
        ExcelUtil<KKUser> util = new ExcelUtil<KKUser>(KKUser.class);
        return util.exportExcel(list, "kkuser");
    }

    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("user:kkuser:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(KKUser kKUser)
    {
        return toAjax(kKUserService.insertKKUser(kKUser));
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        KKUser kKUser = kKUserService.selectKKUserById(id);
        mmap.put("kKUser", kKUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("user:kkuser:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(KKUser kKUser)
    {
        return toAjax(kKUserService.updateKKUser(kKUser));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("user:kkuser:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(kKUserService.deleteKKUserByIds(ids));
    }
}
